package com.admin;

import com.tiangong.framework.enable.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@EnableTransactionManagement
@EnableRestController                       //启用框架不带跨域
//@EnableCrossOriginRestController          //启用框架带跨域
//@EnableNettyServer                        /启用netty服务端
//@EnableNettyClient                        //启用netty客户端
@EnableEventHandler                         //启用异步事件
@EnableRedisBuiltIn                         //启用内置redis
@EnableCache                                //启用redis缓存
@EnableServiceFilter                        //启用servie过滤
@EnableTrigger                              //启用触发器
@Slf4j
public class TiangongApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(TiangongApplication.class, args);
        Environment env = application.getEnvironment();
        String ip=null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path")==null?"":"/"+env.getProperty("server.servlet.context-path");

        log.info("\n----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/rest/v1/serviceName/methodName\n\t" +
                "External: \thttp://"+ip+":"+port+path+"/rest/v1/serviceName/methodName\n" +
                "----------------------------------------------------------");
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TiangongApplication.class);
    }
}
